<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h2>每日新闻订阅</h2>
<div id="msg"></div>
<script src="js/stomp.min.js"></script>
<script>
    //创建表websocket
    const ws = new WebSocket('ws://localhost:8080/message-broker')
    //再将websocket对象包装成stomp客户端
    const stomp = Stomp.over(ws);
    //设置发出心跳的间隔时间(毫秒)
    stomp.heartbeat.outgoing = 30000;
    //设置接收心跳的间隔时间（毫秒）
    stomp.heartbeat.incoming = 30000;
    //连接服务器并订阅消息
    stomp.connect({}, function(){
        //订阅消息
        stomp.subscribe('/news/message', function(data){
            const msg = JSON.parse(data.body);
            //获取消息内容
            document.getElementById('msg').innerHTML += msg.content + '<br>';
        });
    });
</script>
</body>
</html>